package org.dtrd.modules.record.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author 萧
 * @date:2021-10-10 11:45 下午
 **/
@Configuration
@Slf4j
public class SugarConfig {

    @Value("${dtrd.achievement.judgement.normal}")
    private String beforeLow;
    @Value("${dtrd.achievement.judgement.good}")
    private String beforeHigh;
    @Value("${dtrd.achievement.judgement.perfect}")
    private String afterLow;
    @Value("${dtrd.achievement.judgement.bad}")
    private String afterHigh;

    public enum SugarLimit {
        /**
         * 餐前 低
         */
        BEFORE_LOW(1),

        BEFORE_HIGH(2),

        AFTER_LOW(3),

        AFTER_HIGH(4);

        private int type;

        SugarLimit(int type) {
            this.type = type;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public static SugarLimit valueOf(Integer type) {
            for (SugarLimit value : values()) {
                if (value.type == type) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 上下限类型
     */
    public enum UplowType {

        /**
         * 凌晨
         */
        WEE_HOURS(1,6.1f,4.4f),
        /**
         * 空腹
         */
        LIMOSIS(2,6.1f,4.4f),
        /**
         * 餐后
         */
        AFTER_MEAL(3,10.0f,4.4f),
        /**
         * 睡前
         */
        BEFORE_SLEEP(4,7.7f,4.4f),

        /**
         * 餐前
         */
        BEFORE_MEAL(5,7.0f,4.4f),

        /**
         * 收缩压
         */
        PRESSURE_HIGH(6, 100f, 120f),

        /**
         * 舒张压
         */
        PRESSURE_LOW(7, 60f, 80f),

        /**
         * bmi
         */
        BMI(8, 18.5f, 23.9f);

        int type;
        float defaultLimitUp;
        float defaultLimitLow;

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public float getDefaultLimitUp() {
            return defaultLimitUp;
        }

        public float getDefaultLimitLow() {
            return defaultLimitLow;
        }

        UplowType(int type, float defaultLimitUp, float defaultLimitLow) {
            this.type = type;
            this.defaultLimitUp = defaultLimitUp;
            this.defaultLimitLow = defaultLimitLow;
        }

        public static UplowType valueOf(Integer type){
            for (UplowType value : values()) {
                if (value.type == type) {
                    return value;
                }
            }
            return null;
        }

        public static UplowType valueOfName(String name){
            for (UplowType value : values()) {
                if (value.name().equals(name)) {
                    return value;
                }
            }
            return null;
        }
    }

    public String getSugarLimit(int type) {
        SugarLimit state = SugarLimit.valueOf(type);
        String notice = null;
        if (state != null) {
            switch (state) {
                case BEFORE_LOW:
                    notice = beforeLow;
                    break;
                case BEFORE_HIGH:
                    notice = beforeHigh;
                    break;
                case AFTER_LOW:
                    notice = afterLow;
                    break;
                case AFTER_HIGH:
                    notice = afterHigh;
                    break;
                default:
                    break;
            }
        } else {
            notice = beforeLow;
        }
        return notice;
    }
}
